package cn.tworice.admin.service.impl;

import cn.tworice.admin.service.CrudService;
import cn.tworice.admin.service.InductsListenerService;
import cn.tworice.admin.dao.VersionLogDao;
import cn.tworice.common.entity.VersionLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VersionLogService implements InductsListenerService<VersionLog>, CrudService<VersionLog> {
    @Autowired
    private VersionLogDao dao;

    public List<VersionLog> getList(Integer page, Integer pageSize, VersionLog entity) {
        return dao.queryList(page * pageSize, pageSize, entity);
    }

    public int getTotal(VersionLog entity) {
        return dao.queryTotal(entity);
    }

    public int set(VersionLog entity) {
        if (entity.getId() == null) {
            entity.setDate(System.currentTimeMillis());
            return dao.insert(entity);
        } else {
            return dao.update(entity);
        }
    }

    public int del(Integer[] ids) {
        return dao.del(ids);
    }

    @Override
    public int save(List<VersionLog> list) {
        list.forEach(item -> {
            item.setDate(System.currentTimeMillis());
        });
        return dao.insertList(list);
    }

    public VersionLog getInfo(Integer id) {
        return dao.queryInfo(id);
    }
}